DEVICE COUNTER2

0.1 Introduction

0.2 Installation

0.2.1 Device declaration in the configuration file (.CNF)

In the configuration file (.CNF), the BUS section must be declared so that you have the hardware resources required for the implementation of the COUNTER2 device. There must be at least one bidirectional meter. The device can also use an interrupt line for the snap functions count on interrupt (such as uploading preset quota).
In the INTDEVICE section of the .CNF file must be added the following definition:

;---------------------------------
; Internal device declaration
;---------------------------------
INTDEVICE
..
<device_name> COUNTER2 TCamp QCTL IntL
:info:It is necessary that each definition are present on the same line. In case you do not want to assign a resource such as IntL, you still must enter in the appropriate field the string X.

where:

<device name>Name assigned to the device.
COUNTER2Keyword that identifies the device bi-directional meter.
TCampSample time device (1÷255 ms).
QCTLAddress tab counter.
IntLHardware interrupt line number dedicated for transducer zero pulse during the capture phase of the count (to prevent the device uses this resource to put the X character).

0.2.1.1 Example

;---------------------------------
; Internal device declaration
;---------------------------------
INTDEVICE
Count  COUNTER2  2  2.CNT02  3

0.3 Operation

0.3.1 Transducer resolution

To use the device you must define the transducer resolution.
cntratio = (space covered in units of measure / pulses turn encoder) x 100000
This allows conversion constant to transduce the pulses read in space covered by the axis. The relationship space/pulse can assume values between 0,00374 eand 4,00000 but, having to be introduced in an integer parameter, must be multiplied by 100000.
Once set correctly the resolution it will be possible to read the instantaneous position of the axis (in unit of measure) on the posit parameter.

0.3.2 Operations with counting

You can lock and unlock the updating with CNTLOCK andCNTUNLOCK commands.
You can reverse and restore the counter direction with CNTREV and CNTDIR commands.

0.3.3 Fast acquisition of counting on hardware interrupts

The INTENBL and INTDSBL commands enable and disable the interrupt line connected to the transducer's zero pulse. The value of the capture parameter defines on which this impulse will be frozen on instantaneous count; the count caught is placed in the delta parameter.

0.3.4 Delta count

:info:The modify of the resolution value (cntratio) or the writing of the posit variable, causes the reset of the remnants of the conversion.

The device always shows the absolute position of the axis; the counter change can be executed alsowith the direct writing in the new value on the posit paramenter.
Wanting to steal 100 units of measure to the count you can:
Axis:posit = Axis:posit - 100
This introduces an error because it imposes the location “posit = -100”, when the axis could have an intermediate position between a unit of measurement and subsequent (esxample 100.3). This fraction (0.3) is lost and the repetition of these steps will the accumulation of a considerable error.
The DELCNT command sum at the count an amount equal to thedelta parameter without losing the fraction part of the position:
Axis:delta = -100
DELCNT Axis

0.3.4.1 Example

The reading of the axis is of 2 units and is located at point A. You want to add to the count posit three units of measure.
With the instructions:
Axis:posit = Axis:posit + 2
the axis takes the new B position.
With the instructions:
Axis:delta = 2
DELCNT Axis
the axis takes the C position C.

Note that with the first instructions the axis took a delta less than 3 units and then introduced an error.
If you need to send DELCNT commands in succession, It is convenient to calculate the greatness to be summed and send once the command; otherwise Beware not to send subsequent commands without a read statement on device parameter.

0.3.4.2 Example

Axis:delta = 3
DELCNT Axis
WAIT Axis:st_init
Axis:delta = 40
DELCNT Axis

0.4 Commands and parameters table

0.4.1 Symbols used

The name of the parameter, state oo command comando is shown to the left side of the table.

R
Indicates whether its parameter or state is retentive (upon initialization of the device maintains the previously state defined), or the state assumes upon initialization of the device.
If the device does not need to initialize the field “R” indicates the value that the parameter or state presenting to power up of the card.
R = Retentive
0 = Upon initialization of the device the value is forced to zero.
1 = Upon initialization of the device the value is forced to one.
- = Upon initialization of the device is presented significant value.

D
Indicates the size of the parameter.
F = Flag
B = Byte
W = Word
L = Long
S = Single Float

0.4.1.1 Conditions

Describes all of the conditions that is considered correct or because the command is accepted.
In some cases, limit values are specified for the acceptance of the parameter: if introduce any values outside the limits set, the data is still accepted; therefore appropriate controls of the application must be provided to ensure the proper functioning.
To run a command, all conditions must be met; otherwise, the command is not sent.

A
Indicates the access mode.
R = Read.
W = Write.
RW = Read / Write.

0.4.2 Commands

The commands were ranked by decreasing priority. For example, in the case of contemporary of CNTLOCK andCNTUNLOCK commands, is acquired first the CNTLOCK command.

NameConditionsDescription
CNTLOCKst_init = 1Counter lock
Blocks the acquisition of axis count even if the transducer continues to send signals. At this stage the possible displacement of the axis is not detected.
Activates the st_cntlock state.
CNTUNLOCKst_init = 1Counter unlock
Unlock the axis count. Is rehabilitated the updating of the count.
Disable the st_cntlock state.
CNTREVst_init = 1Counter reverse
Invert the phases of the transducer inside the card. Is then reversed the direction of the count (increase/decrease).
Activates the st_cntrev state.
CNTDIRst_init = 1Counter direct
The axis counting is not reversed. Disable the st_cntrev state.
INTENBLst_init = 1
capture>0
1£ IntL £ 8
Interrupt enable
Enable capture of the count that will be stored in delta.
Activates the st_intenbl state.
INTDSBLst_init = 1Interrupt disable
Disable the count capture.
Disable the st_intenbl state.
RSCAPTUREst_init = 1Reset capture
Disable the st_capture state.
DELCNTst_init = 1
st_intenbl = 0
Delta counter
The count (axis position) is changed by adding algebraically the value specified in the delta parameter (posit = posit + delta).

0.4.3 Parameters

NameDRAConditionsDescription
cntratioLRR-WNoCounter ratio
Defines how the transducer pulses must be multiplied so that the acquisition of movements is expressed in the unit of measure desired. By setting 100000 the count variation is 1 bit per pulse transducer.
Valid range: 374 ÷ 400000
positLRR-WNoActual position
Is the value of the instantaneous position of the axis.
Value expressed in units of measurement (Um).
Valid range: -999999 ÷ 999999
deltaLRR-WNoDelta counter
Is the value that is added to the count when sending a DELCNT command.
Value expressed in units of measurement (Um).
Valid range: -999999 ÷ 999999.
captureBRR-WNoCapture mode
Defines how to count is captured on hardware interrupts.
0 = Disable.
1 = Single capture on falling edge.
2 = Single capture on the rising edge.
N.B. The capture of the counting is enabled if the state st_intenbl = 1.

0.4.4 Stati

NomeDRACondizioniDescrizione
st_cntlockFRRNessunaCounter locked
Segnalazione di conteggio asse bloccato.
0 = Conteggio asse sbloccato.
1 = Conteggio asse bloccato.
st_cntrevFRRNessunaCounter reversed
Segnalazione di conteggio asse invertito.
0 = Conteggio asse non invertito.
1 = Conteggio asse invertito.
st_intenblF0RNessunaInterrupt enabled
Segnala l'abilitazione alla cattura del conteggio da linea di interrupt hardware. Viene attivato dal comando INTENBL e disattivato dal comando INTDSBL. viene disattivato automaticamente a cattura avvenuta.
0 = Cattura del conteggio non è abilitata.
1 = Cattura del conteggio abilitata.
st_captureF0RNessunaCounter capture
Viene attivato alla cattura del conteggio; viene resettato dal comando RSCAPTURE.
0 = Cattura del conteggio non eseguita.
1 = Eseguita cattura conteggio.

0.5 Limitazioni

Se viene modificato il parametro cntratio successivamente all’invio del comando DELCNT, vengono azzerati i resti della conversione del “delta spazio” in impulsi.

0.6 Esempio applicativo

0.6.1 File di configurazione

;*************************************************************************************
; Nome Modulo: Ex_Count.CNF                        Progetto: Ex_COUNT
; Autore: QEM srl                                  Data : 01/05/99
; Sistema: QMove1 / QCL3                           Libreria: 1LIB3B04
; Funzionalità: Esempio gestione CPUNTER           Release: 0
;------------------------------------- Note ------------------------------------------
; [1] - Applicativo di esempio per utilizzo device COUNTER 2
;*************************************************************************************
 
;-------------------------------------------------------------------------------------
; Definizione Costanti
;-------------------------------------------------------------------------------------
CONST
 
;-------------------------------------------------------------------------------------
; Definizione Variabili SYSTEM
;-------------------------------------------------------------------------------------
SYSTEM
slPrsPos  L                               ;Quota di preset
slSet1    L                               ;Setpoint 1
slSet2    L                               ;Setpoint 2
 
;-------------------------------------------------------------------------------------
; Definizione Variabili GLOBAL
;-------------------------------------------------------------------------------------
GLOBAL
 
;-------------------------------------------------------------------------------------
; Definizione Variabili TIMER
;-------------------------------------------------------------------------------------
TIMER
 
;-------------------------------------------------------------------------------------
; Definizione DATAGROUP
;-------------------------------------------------------------------------------------
;DATAGROUP
 
;-------------------------------------------------------------------------------------
; Configurazione Bus
;-------------------------------------------------------------------------------------
BUS
    1   1CPUB   02
    2   1MIXA   00
    3   .
    4   .
 
;-------------------------------------------------------------------------------------
; Definizione Variabili INPUT
;-------------------------------------------------------------------------------------
INPUT
ifAbilZ     F    2.INP01                 ;Abilitazione cattura impulso di zero
ifAxeFermo  F    2.INP02                 ;Segnalazione asse fermo
 
;-------------------------------------------------------------------------------------
; Definizione Variabili OUTPUT
;-------------------------------------------------------------------------------------
OUTPUT
ofGTSet1    F    2.OUT01                 ;Segnalazione superamento setpoint 1 ->
ofLTSet2    F    2.OUT02                 ;Segnalazione superamento setpoint 2 <-
 
;-------------------------------------------------------------------------------------
; Dichiarazione device interni
;-------------------------------------------------------------------------------------
INTDEVICE
;Nome  Tipo     TCamp   Contatore   Inter
Asse   COUNTER2 2       2.CNT01     1
 
END

0.6.2 Gestione COUNTER2

;*************************************************************************************
; Nome File: TASK_00.MOD
; Progetto : EX_COUNT
; Descrizione:Gestione Posizionamento
;*************************************************************************************
 
;-------------------------------------------------------------------------------------
; Operazioni di Inizializzazione Asse
;-------------------------------------------------------------------------------------
Asse:cntratio = 100000                          ;Risoluz.encoder = Spazio in 1 giro
                                                ;encoder(Um) / impulsi giro encoder
Asse:capture = 1
IF slSet1 EQ 0
  slSet1 = 500
ENDIF
IF slSet2 EQ 0
  slSet2 = 100
ENDIF
 
;-------------------------------------------------------------------------------------
; Ricerca di preset abilitata ad ogni passaggio sul finecorsa
; ---------------------------- variabili utilizzate ---------------------------------
; slPrsPos : Quota di preset impostata
;--------------------------------------------------------------------------------------
MAIN:
  IF ifAbilZ                                    ;Attende l'ingresso di abilitazione
                                                ;impulso di zero trasduttore
    INTENBL Asse                                ;Abilita la cattura dell'impulso di zero
                                                ;trasduttore
  ELSE
    INTDSBL Asse                                ;Disabilita la cattura dell'impulso di
                                                ;zero trasduttore
  ENDIF
 
IF Asse:st_capture                              ;Se è stato catturato il conteggio
  IF ifAxeFermo                                 ;Se l'asse è fermo
    Asse:delta = -(Asse:delta-slPrsPos)         ;Calcolo quota da sommare al conteggio
    DELCNT Asse                                 ;Imposto il nuovo valore del conteggio
    RSCAPTURE Asse                              ;Resetto st_capture dell'Asse
  ENDIF
ENDIF
 
;-------------------------------------------------------------------------------------
; Comparazioni sul conteggio
; ----------------------------- variabili utilizzate --------------------------------
; slSet1: Quota di comparazione per uscita ofGTSet1
; slSet1: Quota di comparazione per uscita ofLTSet2
;-------------------------------------------------------------------------------------
IF Asse:posit GT slSet1                         ;Se il conteggio è > del setpoint 1
  SETOUT ofGTSet1                               ;Attiva l'uscita ofGTSet1
ELSE
  RESOUT ofGTSet1                               ;Disattiva l'uscita ofGTSet1
ENDIF
IF Asse:posit LT slSet2                         ;Se il conteggio è < del setpoint 2
  SETOUT ofLTSet2                               ;Attiva l'uscita ofLTSet2
ELSE
  RESOUT ofLTSet2                               ;Disattiva l'uscita ofLTSet2
ENDIF
 
;-------------------------------------------------------------------------------------
; Operazioni finali
;-------------------------------------------------------------------------------------
  WAIT 1
  JUMP MAIN
 
END